<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        var generate = function(numRows) {
            let res = [[1],[1,1]]
            if(numRows === 1) return [1]
            if(numRows === 2) return res
            for (let i=2;i<numRows;i++){
                let arr = []
                for (let j=0;j<=i;j++){
                    if(j === 0 || j === i){
                        arr.push(1)
                    }else{
                        arr.push(res[i-1][j-1]+res[i-1][j])
                    }
                }
                res.push(arr)
            }
            return res
        }
        console.log(generate(1))
    </script>
</body>
</html>